﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace Windows8Accelerator.Core.Xaml.Controls.Charts
{
    public class IntDoubleDataSerie : DependencyObject, IDataSerie
    {
        public IntDoubleDataSerie()
        {
            Data = new ObservableCollection<DataPoint<int, double>>();
        }

        public ObservableCollection<DataPoint<int, double>> Data
        {
            get { return (ObservableCollection<DataPoint<int, double>>)GetValue(DataProperty); }
            set { SetValue(DataProperty, value); }
        }
        public static readonly DependencyProperty DataProperty =
            DependencyProperty.Register("Data", typeof(ObservableCollection<DataPoint<int, double>>), typeof(IntDoubleDataSerie), new PropertyMetadata(null));


        public double GetMinY()
        {
            return Data.Select((d) => d.Y).Min();
        }

        public double GetMaxY()
        {
            return Data.Select((d) => d.Y).Max();
        }

        public double GetMinX()
        {
            return Data.Select((d) => d.X).Min();
        }

        public double GetMaxX()
        {
            return Data.Select((d) => d.X).Max();
        }


        public double GetCount()
        {
            return Data.Count;
        }

        public object GetItem(int index)
        {
            return Data[index];
        }

        public DataTemplate GetItemTemplate()
        {
            var resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("ms-appx:///W8A.C.X/Themes/Generic.xaml");
            return resourceDictionary["IntDoubleDataItemTemplate"] as DataTemplate;
        }


        public double GetYAsDouble(int index)
        {
            return Data[index].Y;
        }

        public double GetXAsDouble(int index)
        {
            return Data[index].X;
        }


        public object GetX(int index)
        {
            return Data[index].X;
        }

        public string GetXLabel(int index)
        {
            return Data[index].XLabel;
        }

        public object GetY(int index)
        {
            return Data[index].Y;
        }

        public string GetYLabel(int index)
        {
            return Data[index].YLabel;
        }


        public DataTemplate GetXLabelTemplate()
        {
            var resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("ms-appx:///W8A.C.X/Themes/Generic.xaml");
            return resourceDictionary["XLabelDataTemplate"] as DataTemplate;
        }


        public DataTemplate GetYLabelTemplate()
        {
            var resourceDictionary = new ResourceDictionary();
            resourceDictionary.Source = new Uri("ms-appx:///W8A.C.X/Themes/Generic.xaml");
            return resourceDictionary["YLabelDataTemplate"] as DataTemplate;
        }

        public Func<double, string> YValueToString
        {
            get;
            set;
        }
    }
}
